﻿CREATE TABLE [fb].[Product] (
    [ProductId]      INT            IDENTITY (1, 1) NOT NULL,
    [Name]           NVARCHAR (200) NOT NULL,
    [Description]    NVARCHAR (MAX) NULL,
    [Status]         INT            NOT NULL,
    [Version]        INT            NOT NULL,
    [CreatedDate]    DATETIME       NOT NULL,
    [UpdatedDate]    DATETIME       NOT NULL,
    [ParentId]       INT            NULL,
    [CounterpartyId] INT            NULL,
    CONSTRAINT [PK_fb.Product] PRIMARY KEY CLUSTERED ([ProductId] ASC),
    CONSTRAINT [FK_fb.Product_fb.Counterparty_CounterpartyId] FOREIGN KEY ([CounterpartyId]) REFERENCES [fb].[Counterparty] ([CounterpartyId]),
    CONSTRAINT [FK_fb.Product_fb.Product_ParentId] FOREIGN KEY ([ParentId]) REFERENCES [fb].[Product] ([ProductId])
);


GO
CREATE NONCLUSTERED INDEX [IX_ParentId]
    ON [fb].[Product]([ParentId] ASC);


GO
CREATE NONCLUSTERED INDEX [IX_CounterpartyId]
    ON [fb].[Product]([CounterpartyId] ASC);

